# -*- coding: utf-8 -*-
import scrapy


class BlogSpider(scrapy.Spider):
    name = 'blog'
    allowed_domains = ['blog.csdn.net']
    start_urls = ['https://blog.csdn.net/kuangshp128/article/list/{0}'.format(i) for i in range(1, 13)]

    def parse(self, response):
        all_li = response.css('div.article-list .article-item-box')

        for li in all_li:
            url = li.css('.text-truncate a::attr(href)').extract_first()
            print('当前的url地址:{0}'.format(url))
            yield scrapy.Request(url=url, callback=self.article)

    def article(self, response):
        print('详细页面标题===>:', response.css('.title-article::text').extract_first())
